package com.xxxx.aop;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created By ShaoXikai on 2022/7/21
 */
@Component
@Aspect
public class OnceAdvice {
    // 定义切点
    @Pointcut("execution(* com.xxxx.dao.BookDao.*d*(..))")
    private void pt() {
    }

    @Pointcut("execution(* com.xxxx.dao.BookDao.*(..))")
    private void pc() {
    }

    @Pointcut("execution(* com.xxxx.dao.*.*(..))")
    private void pd() {
    }

    @Before("pd()")
    public void before() {
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
        System.out.println("开始执行！");
    }

    @After("pd()")
    public void after() {
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
        System.out.println("执行完毕！");
    }

}
